﻿using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = int.Parse(Console.ReadLine());
        }
        int first = 0;
        int last = 0;
        int sum = 0;
        int max = int.MinValue;
        int s = 11;
        for (int i = 0; i < n; i++)
        {
            sum = sum + arr[i];
            if (sum < 0)
            {
                if (sum != s)
                {
                    sum = 0;
                    first = i + 1;
                }
                else
                {
                    break;
                }
            }
            if (sum > max)
            {
                if (sum != s)
                {
                    max = sum;
                    last = i;
                }
                else
                {
                    break;
                }
            }
        }
        Console.WriteLine(sum);
        for (int i = first; i < last + 1; i++)
        {
            Console.WriteLine(arr[i] + " ");
        }
    }
}